import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import {
    AddDataButton,
    ModDataButton,
    DelDataButton,
    OpenThrTouter,
    ExamineButton,
    AnnexButton,
} from '../Common/options'

export const SampleReport = async ({ OptionsEvent, oneData, Permission, actionRef }) => {
    let dataList = {
        uuid: oneData.uuid,
        hideInSearch: true,
        pageSize: 10,
        params: { sampleUuid: oneData.uuid },
        initialValues: { sampleUuid: oneData.uuid },
        get: API_LIST()['getSampleReportAttachment'],
        added: 'posSampleReportAttachment',
        options: [
            Permission.findIndex(v => v.uuid === 'f39c340a-afa9-4f1c-b8cd-e398bde8b83a') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="上传检测报告" />
            ),
        ],
        columns: [
            {
                dataIndex: 'sampleUuid',
                title: 'SampleUuid',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
            },
            {
                dataIndex: 'originalName',
                title: '报告名称',
                valueType: 'hidden',
                search: false,
                hideInAdded: true,
                hideInModify: true,
            },
            {
                dataIndex: 'createUserName',
                title: '上传人',
                valueType: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
            },
            {
                dataIndex: 'createTime',
                title: '上传时间',
                valueType: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
            },
            {
                dataIndex: 'attachmentUuid',
                title: '样品报告附件',
                valueType: 'upload',
                valueFile: [1, 2, 3, 4, 5],
                fileUrl: 'fileUrl',
                rules: true,
                hideInTable: true,
            },
            {
                dataIndex: 'fileUrl',
                title: '样品附件',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
                hideInAdded: true,
                hideInModify: true,
                width: 400,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, fileUrl } = record
                    return [
                        fileUrl && <AnnexButton OptionsEvent={OptionsEvent} key="see" url={fileUrl} title="查看附件" />,
                        Permission.findIndex(v => v.uuid === '57757faf-6112-4cf2-bb3a-e2ded83517df') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url="SampleReportAttachment"
                                uuid={uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return dataList
}
